define(function(require, exports, module) {

	var $ = require('jquery');
	require('jbox');
	require('../util/tinymce-admin-page.js');	
	require('jquery/jquery-file-upload/8.8.5/vendor/jquery.ui.widget.js');
	require('jquery/jquery-file-upload/8.8.5/jquery.iframe-transport.js');
	require('jquery/jquery-file-upload/8.8.5/jquery.fileupload.js');

	

	//加载
	var url = $CONFIG.base_url + '/api/configure/get';
	$.get(url,function(data){
		info = data;
		tinymce.init({
			selector : 'textarea#protrol',
			theme : "modern",
			plugins : [ "preview image table contextmenu",
			            "emoticons paste textcolor"],
			            toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
			            toolbar2: "print preview media | forecolor backcolor emoticons",
			language : 'zh_CN',
			height:'300px',
			file_browser_callback : function(field_name, url, type, win) {
				if (type == 'image') {
					$('#fileupload').click();
				}
			},
			init_instance_callback:load,
		});
		function load(inst){
			$("#protrol_ifr").contents().find("#tinymce").html(info.projectProtrol);
		}
	});

	//更新服务协议
	$("#save").click(function(){
		var protrol = tinyMCE.get('protrol').getContent();
		$.ajax({
			url: $CONFIG.base_url + '/api/configure/update',
			type:'POST',
			data:{'projectProtrol':protrol},
			success : function(data) {
					if(data)
					$.jBox.tip('更新成功~');
				else
					$.jBox.tip('更新失败~');
			},
			error : function() {
				$.jBox.tip('亲~出问题啦，请再试一次！');
			}
		})
			
	})
})